
//顶点对象
function jewel_vao_gen(gl, programInfo){
	
	//buffers
	const VAO = gl.createVertexArray();
	gl.bindVertexArray(VAO);
	const VBO = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, VBO);
	{
	const factor_scale = 0.6;//小菱形相对大菱形的比值
	const ratio_width_height = 0.55;//菱形宽度相对高度的比值
	const distance = 0.1;//菱形的间距

	let diamond = [
		//菱形平面
		ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,
		0, factor_scale, -distance,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,

		-ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,
		0, -factor_scale, -distance,	0, 0, 0,
		ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,
		

		-ratio_width_height * factor_scale, 0, distance,	0, 0, 0,
		0, factor_scale, distance,	0, 0, 0,
		ratio_width_height * factor_scale, 0, distance,	0, 0, 0,

		ratio_width_height * factor_scale, 0, distance,	0, 0, 0,
		0, -factor_scale, distance,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, distance,	0, 0, 0,


		//菱形连接处
		ratio_width_height, 0, 0,	0, 0, 0,
		0, 1, 0,	0, 0, 0,
		0, factor_scale, -distance,	0, 0, 0,

		ratio_width_height, 0, 0,	0, 0, 0,
		0, factor_scale, -distance,	0, 0, 0,
		ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,

		0, 1, 0,	0, 0, 0,
		-ratio_width_height, 0, 0,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,

		0, 1, 0,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,
		0, factor_scale, -distance,	0, 0, 0,

		-ratio_width_height, 0, 0,	0, 0, 0,
		0, -1, 0,	0, 0, 0,
		0, -factor_scale, -distance,	0, 0, 0,

		-ratio_width_height, 0, 0,	0, 0, 0,
		0, -factor_scale, -distance,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,

		0, -1, 0,	0, 0, 0,
		ratio_width_height, 0, 0,	0, 0, 0,
		ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,

		0, -1, 0,	0, 0, 0,
		ratio_width_height * factor_scale, 0, -distance,	0, 0, 0,
		0, -factor_scale, -distance,	0, 0, 0,

		//镜像复制
		-ratio_width_height, 0, 0,	0, 0, 0,
		0, 1, 0,	0, 0, 0,
		0, factor_scale, distance,	0, 0, 0,

		-ratio_width_height, 0, 0,	0, 0, 0,
		0, factor_scale, distance,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, distance,	0, 0, 0,

		0, 1, 0,	0, 0, 0,
		ratio_width_height, 0, 0,	0, 0, 0,
		ratio_width_height * factor_scale, 0, distance,	0, 0, 0,

		0, 1, 0,	0, 0, 0,
		ratio_width_height * factor_scale, 0, distance,	0, 0, 0,
		0, factor_scale, distance,	0, 0, 0,

		ratio_width_height, 0, 0,	0, 0, 0,
		0, -1, 0,	0, 0, 0,
		0, -factor_scale, distance,	0, 0, 0,

		ratio_width_height, 0, 0,	0, 0, 0,
		0, -factor_scale, distance,	0, 0, 0,
		ratio_width_height * factor_scale, 0, distance,	0, 0, 0,

		0, -1, 0,	0, 0, 0,
		-ratio_width_height, 0, 0,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, distance,	0, 0, 0,

		0, -1, 0,	0, 0, 0,
		-ratio_width_height * factor_scale, 0, distance,	0, 0, 0,
		0, -factor_scale, distance,	0, 0, 0,
	];


	//法向量计算
	for(let i = 0;i < 20;i += 1){
		let v1 = [
			diamond[i * 18] - diamond[i * 18 + 6],
			diamond[i * 18 + 1] - diamond[i * 18 + 6 + 1],
			diamond[i * 18 + 2] - diamond[i * 18 + 6 + 2],
		];
		
		let v2 = [
			diamond[i * 18 + 12] - diamond[i * 18 + 6],
			diamond[i * 18 + 12 + 1] - diamond[i * 18 + 6 + 1],
			diamond[i * 18 + 12 + 2] - diamond[i * 18 + 6 + 2],
		];
		
		let norm = normal_gen(v1, v2);
		
		for(let j = 0;j < 3;j += 1){
			diamond[i * 18 + j * 6 + 3] = norm[0];
			diamond[i * 18 + j * 6 + 3 + 1] = norm[1];
			diamond[i * 18 + j * 6 + 3 + 2] = norm[2];
		}
	}
		
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(diamond), gl.STATIC_DRAW);
	
		
	}

		
	
	gl.vertexAttribPointer(
		programInfo.attribLocations.vertexPosition,
		3,
		gl.FLOAT,
		false,
		24,
		0,
	);
	gl.vertexAttribPointer(
		programInfo.attribLocations.normPosition,
		3,
		gl.FLOAT,
		false,
		24,
		12,
	);

	gl.enableVertexAttribArray(programInfo.attribLocations.vertexPosition);
	gl.enableVertexAttribArray(programInfo.attribLocations.normPosition);
	
	
	return VAO;
}